<?php

namespace App\Admin\Controllers;

use App\Enums\AccountAction;
use App\Models\AccountLog;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;

class AccountLogController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new AccountLog(), function (Grid $grid) {
            $grid->model()->with(['account.user'])->orderByDesc('id');
            $grid->column('id')->sortable();
            $grid->column('account.user.mobile', '手机号');
            $grid->column('account.user.email', '邮箱');
            $grid->column('account.coin', '币种');
            $typeArray = [
                AccountAction::Deposit->name => '用户充值',
                AccountAction::WithdrawCreated->name => '提现申请',
                AccountAction::WithdrawCancelled->name => '提现取消',
                AccountAction::WithdrawPass->name => '提现通过',
                AccountAction::PayServiceFee->name => '服务费',
                AccountAction::TransFrom->name => '转账-转出',
                AccountAction::TransTo->name => '转账-转入',
                AccountAction::AdminChange->name => '管理员充值',
                AccountAction::Active->name => '激活',
                AccountAction::RecommendReward->name => '推荐盈利',
                AccountAction::TeamReward->name => '社区盈利',
                AccountAction::GroupReward->name => '团队盈利',
                AccountAction::Exchange->name => '兑换',
            ];
            $grid->column('type', '类型')->using($typeArray);
            $grid->column('free_before', '操作前可用余额');
            $grid->column('free_change', '可用数量变化');
            $grid->column('free_after', '操作后可用余额');
            $grid->column('lock_before', '操作前冻结金额');
            $grid->column('lock_change', '冻结金额变化');
            $grid->column('lock_after', '操作后冻结金额');
            $grid->column('created_at');

            $grid->filter(function (Grid\Filter $filter) use ($typeArray) {
                $filter->equal('id');
                $filter->equal('account.user.email', '邮箱');
                $filter->equal('account.user.mobile', '手机');
                $filter->equal('account.coin', '币种');
                $filter->equal('type', '类型')->select($typeArray);
            });

            $grid->disableBatchDelete();
            $grid->disableRowSelector();
            $grid->disableActions();
            $grid->disableCreateButton();
        });
    }
}
